<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            user-select: none;
        }
    </style>
</head>

<body>
    <h1>点击给网页设置随机颜色</h1>
    <script>

        function getRandomColor() {
            return '#' + Math.random().toString(16).substring(2, 8);
        }

        var h1 = document.getElementsByTagName('h1')[0]
        document.addEventListener('click', function () {
            document.body.style.backgroundColor = getRandomColor();
            h1.style.color = getRandomColor();
        })
    </script>
</body>

</html>